package com.mojiayi.learn.common.result;

/**
 * 分页结果.
 *
 * @param <T> 返回结果对象
 */
public class PageResultSet<T> extends ListResultSet<T> {
    private static final long serialVersionUID = -6934915596085958833L;

    /** 当前页码. **/
    private int pageIndex = 1;
    /** 默认每页的数量. **/
    private int pageSize = 10;
    /** 每页条件查询出来的总数量. **/
    private int totalItem;

    /**
     * 构造方法.
     */
    public PageResultSet() {
    }

    /**
     * 构造方法.
     * 
     * @param currentPage 当前页码
     * @param pageSize 每页数量
     */
    public PageResultSet(int currentPage, int pageSize) {
        if (currentPage > 0) {
            this.pageIndex = currentPage;
        }
        if (pageSize > 0) {
            this.pageSize = pageSize;
        }
    }

    /**
     * 总页数.
     * @return int
     */
    public int totalPage() {
        int totalPage = (totalItem + pageSize - 1) / pageSize;
        return totalPage;
    }

    public int getCurrentPage() {
        return pageIndex;
    }

    /**
     * 设置当前页码.
     * 
     * @param currentPage 当前页码
     */
    public void setCurrentPage(int currentPage) {
        if (currentPage > 0) {
            this.pageIndex = currentPage;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    /**
     * 设置每页数量.
     * 
     * @param pageSize 每页数量
     */
    public void setPageSize(int pageSize) {
        if (pageSize > 0) {
            this.pageSize = pageSize;
        }
    }

    public int getTotalCount() {
        return totalItem;
    }

    /**
     * 设置总数.
     * 
     * @param totalCount 总数
     */
    public void setTotalCount(int totalCount) {
        if (totalCount > 0) {
            this.totalItem = totalCount;
        }
    }
}
